package com.qf.commerce.resp;

import lombok.Data;

/**
 * @author zhangwei
 */
@Data
public class ResponseResult<T> {
    /**
     * 英文
     */
    private String message;
    /**
     * 业务状态码
     */
    private int code;
    /**
     * 业务数据
     */
    private T data;


    private ResponseResult() {
    }

    /**
     * 成功失败
     */

    public static <T> ResponseResult<T> success(ResponseStatus responseStatus, T data) {
        return common(responseStatus.getCode(), responseStatus.getMessage(), data);
    }

    public static <T> ResponseResult<T> success(T data) {
        return success(ResponseStatus.SUCCESS, data);
    }

    public static <T> ResponseResult<T> fail() {
        return fail(ResponseStatus.SYS_ERROR);
    }
    public static <T> ResponseResult<T> present() {
        return fail(ResponseStatus.STATE_NOT_PRESENT);
    }
    public static <T> ResponseResult<T> updateFailure() {
        return fail(ResponseStatus.UPDATE_FAILURE);
    }
    public static <T> ResponseResult<T> query() {
        return fail(ResponseStatus.QUERY_FAILURE);
    }
    public static <T> ResponseResult<T> add() {
        return fail(ResponseStatus.ADD_FAILURE);
    }

    public static <T> ResponseResult<T> fail(ResponseStatus responseStatus) {
        return common(responseStatus.getCode(), responseStatus.getMessage(), null);
    }
    public static <T> ResponseResult<T> present(ResponseStatus responseStatus) {
        return common(responseStatus.getCode(), responseStatus.getMessage(), null);
    }

    public static <T> ResponseResult<T> query(ResponseStatus responseStatus) {
        return common(responseStatus.getCode(), responseStatus.getMessage(), null);
    }



    private static <T> ResponseResult<T> common(int code, String message, T data) {
        ResponseResult<T> responseResult = new ResponseResult<T>();
        responseResult.setData(data);
        responseResult.setMessage(message);
        responseResult.setCode(code);
        return responseResult;
    }

}
